3. Longest Substring Without Repeating Characters - LeetCode Solution


Hash String Sliding Window

Python Code:

class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        le = 0
        
        if len(s) ==0:
            return 0
        if len(s) == 1:
            return 1

        ptr1 = 0
        ptr2 = 1



        for i in range(len(s)):

            for j in range(i, len(s)):
                if s[j] in s[i:j]:
                    break
                else:
                    le = max(le, j-i+1)





        return le
            
            
            
            
        


Comments

Submit
0 Comments
More Questions

805B - 3-palindrome
805C - Find Amir
676C - Vasya and String
1042B - Vitamins
1729F - Kirei and the Linear Function
25D - Roads not only in Berland
1694A - Creep
659F - Polycarp and Hay
1040A - Palindrome Dance
372A - Counting Kangaroos is Fun
1396B - Stoned Game
16A - Flag
1056A - Determine Line
670B - Game of Robots
1418C - Mortal Kombat Tower
1382B - Sequential Nim
1272C - Yet Another Broken Keyboard
808A - Lucky Year
1245A - Good ol' Numbers Coloring
58B - Coins
1041C - Coffee Break
507A - Amr and Music
1041D - Glider
1486A - Shifting Stacks
1389B - Array Walk
71B - Progress Bar
701A - Cards
545A - Toy Cars
1538E - Funny Substrings
234A - Lefthanders and Righthanders